
/*
<T>代表当前类是一个泛型类,是一个占位符
 */
class MyArray<T> {
    public Object[] array = new Object[10];
    public void setValue(int pos,T val){
        array[pos] = val;
    }
    public T getValue(int pos){
        return (T)array[pos];
    }
}
public class Test {
    public static void main(String[] args) {
        MyArray<Integer> myArray = new MyArray<Integer>();//只能放包装类或引用类型
        myArray.setValue(0,10);
        myArray.setValue(1,100);

        int a = myArray.getValue(1);
        System.out.println(a);
        MyArray<String> myArray2 = new MyArray<String>();
        myArray2.setValue(0,"abcd");
        myArray2.setValue(1,"efg");
        String ret = myArray2.getValue(0);
        System.out.println(ret);
    }
}
